package com.cdy.server.handler;

import com.cdy.common.command.Command;
import com.cdy.common.response.Response;
import io.netty.channel.ChannelHandlerContext;

import java.util.concurrent.TimeUnit;

/**
 * 服务端命令处理接口
 *
 * Created by 陈东一
 * 2019/10/20 0020 12:22
 */
public interface CommandHandler {
    
    void handle(ChannelHandlerContext ctx, Command msg);


    default void write(ChannelHandlerContext ctx, Response response){
        if (ctx.channel().isWritable()) {
            ctx.writeAndFlush(response);
        } else {
            ctx.channel().eventLoop().schedule(()->write(ctx,response), 1, TimeUnit.MINUTES);
        }
    }
    
}
